The present invention relates to computer graphics, and more particularly to shadow mapping in a graphics pipeline.
A major objective in graphics rendering is to produce images that are so realistic that the observer believes the image is real. A fundamental difficulty in achieving total visual realism is the complexity of accurately representing real world visual effects. A scene can include a wide variety of textures, subtle color gradations, reflections, translucency, etc.
One important way to make images more realistic is to determine how objects in a scene cast shadows and then represent these shadows in the rendered image. Shadows enhance the realism of an image because they give a two-dimensional image a three-dimensional feel.
The addition of shadows to the rendering of a complex model can greatly enhance the understanding of that model""s geometry. The human visual system uses shadows as a cue for depth and shape. Consequently, shadows are very useful for conveying the three-dimensional nature of rendered objects and for adding realism to computer generated scenes.
Prior Art FIG. 1 illustrates a scene to be rendered to include shadows. As shown in Prior Art FIG. 1, a particular scene 100 includes a light source 104, an object 102, and a surface 106. Due to the relative orientation of the light source 104, object 102, and surface 106, a shadow should be shown on the surface 106 where the object 102 obstructs light from the light source 104. Shadow mapping is a technique by which a graphics pipeline may determine which portions of the surface 106 should be rendered with a shadow.
Prior Art FIG. 2 illustrates a prior art technique 200 of shadow mapping. As shown, a light depth value (Zlight) is collected for every portion of the surface 106 that is to be rendered. Such light depth value (Zlight) represents a distance between the light source 104 and the object 102 which may (or may not) be obstructing the light source 104 at a particular portion of the surface 106 that is to be rendered. Traditionally, the light depth value (Zlight) is gathered from a shadow-map that is generated by rendering during a first pass.
Further calculated is an eye depth value (Zeye) that is taken from a perspective of an eye or camera 202 and transformed into the light""s perspective. Such eye depth value (Zeye) represents a distance between the light source 104 and the portion of the surface 106 that is to be rendered.
As is now readily apparent, when the eye depth value (Zeye) is greater than the light depth value (Zlight), it is assumed that the particular portion of the surface 106 should be rendered with a shadow.
A particular problem arises during the foregoing shadow-mapping procedure due to the fact that the light depth value (Zlight) and the eye depth value (Zeye) are sampled from two different viewpoints, which potentially produce slightly different depth values that may cause incorrect shadow results. Specifically, the light depth value (Zlight) is obtained from a point in space sampled from the light source viewpoint 104 of the scene 100, while the eye depth value (Zeye) is obtained from a close-by point in space sampled from the point of the eye 202, and then transformed into the viewpoint of the light source 104. The two points under comparison are close in space, but still may cause a large enough depth difference with respect to the light source 104, which produces unwanted shadow results.
Prior art FIG. 2A illustrates this shadow-mapping problem. FIG. 2A shows a single ray from the light source hitting a horizontal surface and the corresponding texture element (i.e. texel) in the shadow map contained between point xe2x80x98axe2x80x99 and xe2x80x98bxe2x80x99. FIG. 2A also shows three rays (1, 2, and 3) from the eye 202 hitting the same surface 106, which index the single shadow-map texel (all the points inside the [a, b] interval index the same shadow-map texel). Three points on the surface 106 result from the eye viewpoint sampling, and three depth values (Z1, Z2, and Z3) are computed with respect to the light source 104. The comparison of those three depth values with respect to the depth value sampled from the light source point of view illustrates the problem. Clearly, ray number 2 hits the surface exactly at the same point where the light sampled the surface 106 and the comparison of Z2 with respect to the light depth value (Zlight) produces the correct shadow result. However, rays number 1 and 3 may produce opposite results. Ray number 1 produces a z-value (Z1) which is smaller than the light depth value (Zlight) and ray number 3 produces another z-value (Z3) greater than the light depth value (Zlight). The consequence of this difference is that points to the left of the texel center may cause one shadow result, whereas points to the right of the texel center may cause the opposite result, within a given tolerance around the texel center.
In addition to sampling differences between the light and the eye, another problem may also occur. Suppose, in prior art FIG. 2A, that Z2 and the light depth value (Zlight) were produced using different perspective-interpolation methods (i.e. one with pre-perspective divide and the other with post-perspective divide). In such situation, even though the rays from the light and from the eye sample the exact same point on the surface, the use of different perspective-interpolation methods would cause slightly different depth values, which in turn could cause incorrect shadow results.
Unfortunately, these sampling and interpolation problems result in defects in the shadow-mapping algorithm. In particular, portions of the rendered scene that should be shadowed are not, and vice-versa. A common term for describing such defect is xe2x80x9cshadow acne.xe2x80x9d
Various solutions have been proposed to compensate for such problem. For example, one technique (a.k.a. Woo Shadow Mapping Algorithm) utilizes the conventional shadow-mapping methodology, but with an altered light depth value (Zlight). In particular, such algorithm utilizes an average light depth value (Zlight-AVE), which is positioned halfway between the object 102 and the surface 106 that is to be rendered. (Zlight-AVE) is calculated from a first light depth value (Zlight-1) and a second light depth value (Zlight-2). In regions where a single surface is available, the algorithm uses the farthest depth value in the scene (or its average with the single surface available) as the altered depth value.
Prior Art FIG. 3 illustrates the various values 300 utilized to carry out the aforementioned shadow mapping algorithm. Table 1 illustrates the equation that may be used for calculating the average light depth value (Zlight-AVE).
While this technique works well in theory, there are many practical complications that preclude the present shadow mapping algorithm from being implemented in a hardware-implemented graphics pipeline. For example, the second light depth value (Zlight-2) is traditionally not available, or incalculable in a graphics pipeline. Without such second light depth value (Zlight-2), the present shadow mapping algorithm can not be feasibly implemented in a graphics application specific integrated circuit (ASIC), or graphics accelerator.
A system and method are provided for improved shadow mapping in a graphics pipeline. Raw depth values are initially collected from two depth layers in a scene to be rendered. Shadow-map depth values are then calculated utilizing the raw depth values. The scene is then shadow mapped utilizing the shadow-map depth values in order to improve the appearance of shadows in a rendered scene. The various steps are carried out by a hardware-implemented graphics pipeline, which may include texturing or shadowing mapping hardware.
In use, the raw depth values may be collected during an initial two rendering passes from a light perspective. As an option, the shadow-map depth values may be calculated during the second initial rendering pass, and stored in the form of a shadow map. Thereafter, a third rendering pass from an eye perspective may be used to shadow the scene utilizing the shadow map. In one context, shadow mapping may refer to computing a lighting equation for each fragment by taking into account shadows produced by light sources and objects in a scene.
In one embodiment, the shadow-map depth values may include an average (ZLave) of the raw depth values. Further, a plurality of the shadow-map depth values may be calculated to define a pseudo-surface. As an option, the shadow-map depth values (ZLave) may be calculated utilizing first raw depth values (ZL1) of a first depth layer and second raw depth values (ZL2) of a second depth layer utilizing the equation: ZLave=(ZL1+ZL2)/2.
In another embodiment, the scene, as viewed from an eye perspective, may be shadow-mapped by transforming each of a plurality of eye-perspective fragments into a light perspective, and comparing the depth value thereof with a corresponding shadow-map depth value. Further, each fragment may be shadowed if the associated depth value is greater than the corresponding shadow-map depth value.
In still another embodiment, the collection of the raw depth values from the depth layers may be done so in multiple rendering passes. In particular, first raw depth values relating to the first depth layer may be collected during a first rendering pass. As an option, the first raw depth values relating to the first depth layer may take the form of a shadow-map to be used by subsequent rendering passes.
In a similar manner, additional raw depth values relating to the at least one additional depth layer may be collected during at least one additional rendering pass. The at least one additional rendering pass may be taken from an eye position from which a previous rendering pass is taken.
In still another embodiment, the additional raw depth values relating to the at least one additional depth layer may be collected by removing a portion of the scene associated with a previous depth layer. In particular, this may be accomplished by performing a test. In an embodiment where the test works from a front of the scene to a back of the scene, the test determines whether the portion of the scene associated with the previous depth layer is in front of the at least one additional depth layer. If it is determined that the portion of the scene associated with the previous depth layer is in front of the at least one additional depth layer, the particular portion of the scene may be removed. Of course, the test may also work from a front of the scene to a back of the scene.
In one aspect of the present embodiment, the test may calculate differences between z-values relating to the previous depth layers and a z-value relating to the at least one additional depth layer. In operation, a particular portion of the scene may be removed based on a test calculated involving the z-values relating to the previous depth layers and the z-value relating to the at least one additional depth layer.
As an option, the z-values relating to the previous depth layers may be computed using the same hardware method that produces the z-values corresponding to the at least one additional depth layer, which improves accuracy of the tests.
These and other advantages of the present invention will become apparent upon reading the following detailed description and studying the various figures of the drawings.